﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RSSReader.TestConsole.ServiceReference1;


namespace RSSReader.TestConsole
{
  class Program
  {
    static string ArrayToString(string[] source)
    {
      string Res = "";
      for (int i = 0; i < source.Length; ++i)
      {
        if (i != 0)
          Res += ", ";

        Res += source[i];
      }
      return Res;
    }

    static void Main(string[] args)
    {
      //Step 1: Create an instance of the WCF proxy.
      DataDistributorClient client = new DataDistributorClient();

      var UserName = "NewTestUser2";
      var PasswordHash = "APasswordHash";
      var Email = "Procrastination@tomorow.com";

      Console.WriteLine("Trying to get user : {0}", UserName);

      var UserId = client.GetUserId(UserName);

      if (string.IsNullOrEmpty(UserId))
      {
        Console.WriteLine("User not found, creating user {0} (passwordHash : {1}, Email : {2})", UserName, PasswordHash, Email);
        var User = client.CreateUser(UserName, PasswordHash, Email);
        UserId = User.Id;
      }

      Console.WriteLine("UserId is : {0}", UserId);

      var Subs = client.GetSubscriptions(UserId);

      Console.WriteLine("User has sub to : {0}", ArrayToString(Subs));

      Console.WriteLine("Adding subs");
      client.SetSubscriptions(new string[] { "YouPorn.com", "Pornhub.com", "RedTube.com" }, UserId);

      Subs = client.GetSubscriptions(UserId);

      Console.WriteLine("User has sub to : {0}", ArrayToString(Subs));

      Console.WriteLine("Updating feeds");

      Dictionary<string, UserArticleInformation[]> Dico = new Dictionary<string, UserArticleInformation[]>
      {
        { "YouPorn.com", new UserArticleInformation[] { new UserArticleInformation { Url="katsuni", IsFavorite= false }} },
        { "RedTube.com", new UserArticleInformation[] { new UserArticleInformation { Url="emma heart", IsFavorite= true }, new UserArticleInformation { Url="missy stone", IsFavorite= false } }},
        { "Pornhub.com", new UserArticleInformation[] { new UserArticleInformation { Url="hentai", IsFavorite= false }} },
        { "Disney.com", new UserArticleInformation[] { new UserArticleInformation { Url="mikey", IsFavorite= false }} },
      };

      client.UpdateUserArticles(Dico, UserId);

      string[] CheckList = new string[] { "pokemon", "hentai", "fantasia", "emma heart" };

      var RedArticles = client.GetUserArticles(CheckList, UserId);

      string RedArticlesString = "";

      foreach (var kvp in RedArticles)
        RedArticlesString += String.Format("\nSource : {0}, Seen : {1}", kvp.Key, ArrayToString(kvp.Value.Select(s => s.Url).ToArray()));

      Console.WriteLine("from ({0}) user had seen ({1})", ArrayToString(CheckList), RedArticlesString);

      Console.WriteLine("Removing subs");

      client.RemoveSubscriptions(new string[] { "YouPorn.com", "Pornhub.com", "RedTube.com" }, UserId);

      Subs = client.GetSubscriptions(UserId);

      Console.WriteLine("User has sub to : {0}", ArrayToString(Subs));

      ////client.U

      client.Close();
      Console.ReadLine();
    }
  }
}
